﻿using MobleWeiXin.BussinessData;
using MobleWeiXin.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MobleWeiXin.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var model = GetHomeManagerModel();
            return View(model);
        }

        public HomeManagerModel GetHomeManagerModel()
        {
            var result = CacheHelper.GetCache<HomeManagerModel>("HomeManagerModel");
            if (result == null)
            {
                result = new HomeManagerModel();
                result.LasterSlList = new BusinessDataManager().LasterSlList();
                result.Leva1DicList = new BusinessDataManager().Leva1Dic();
                result.Level2List = new BusinessDataManager().Level2List().Take(8).ToList();
                result.WxNavList = new BusinessDataManager().GetWxNavList();
                result.WxNewsList = new BusinessDataManager().GetLasterNews(8);
                result.ArticleList = new BusinessDataManager().GetHotArticleOrVideo(1);
                if (result.LasterSlList.Count > 0 && result.Leva1DicList.Count > 0 && result.Level2List.Count > 0 && result.WxNavList.Count>0 && result.WxNewsList.Count>0 && result.ArticleList.Count>0)
                {
                    CacheHelper.SetCache("HomeManagerModel", result, 60 * 12);
                }
            }
            return result;
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}